package top.zlcode.friend.controller.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import top.zlcode.api.judeg.domain.vo.UserQuestionResultVO;
import top.zlcode.common.core.controller.BaseController;
import top.zlcode.common.core.domain.R;
import top.zlcode.friend.domain.question.dto.FavoriteQuestionDTO;
import top.zlcode.friend.domain.question.dto.FavoriteQueryDTO;
import top.zlcode.friend.domain.question.vo.FavoriteQuestionVO;
import top.zlcode.common.core.domain.TableDataInfo;
import top.zlcode.friend.domain.user.dto.UserSubmitDTO;
import top.zlcode.friend.service.question.IUserFavoriteQuestionService;
import top.zlcode.friend.service.question.IUserQuestionService;

@RestController
@RequestMapping("/user/question")
public class UserQuestionController extends BaseController {

    @Autowired
    private IUserQuestionService userQuestionService;
    
    @Autowired
    private IUserFavoriteQuestionService userFavoriteQuestionService;
    

    /**
     * 用户题目代码提交 弃用版本
     */
    @PostMapping("/submit")
    public R<UserQuestionResultVO> submit(@RequestBody UserSubmitDTO userSubmitDTO) {
        return userQuestionService.submit(userSubmitDTO);
    }

    /**
     * 用户题目代码提交
     */
    @PostMapping("/rabbit/submit")
    public R<Void> rabbitSubmit(@RequestBody @Validated UserSubmitDTO userSubmitDTO) {
        return toR(userQuestionService.rabbitSubmit(userSubmitDTO));
    }

    @GetMapping("/exe/result")
    public  R<UserQuestionResultVO> exeResult(Long examId, Long questionId, String uuid) {
        return R.ok(userQuestionService.exeResult(examId, questionId, uuid));
    }
    
    /**
     * 切换收藏状态
     */
    @PostMapping("/favorite/toggle")
    public R<Boolean> toggleFavorite(@RequestBody @Validated FavoriteQuestionDTO dto) {
        return R.ok(userFavoriteQuestionService.toggleFavorite(dto));
    }
    
    /**
     * 检查是否已收藏
     */
    @GetMapping("/favorite/check")
    public R<Boolean> checkFavorite(@RequestParam Long questionId) {
        return R.ok(userFavoriteQuestionService.checkFavorite(questionId));
    }
    
    /**
     * 获取收藏列表（分页，支持关键词搜索）
     */
    @GetMapping("/favorite/list")
    public TableDataInfo getFavoriteList(FavoriteQueryDTO queryDTO) {
        return getTableDataInfo(userFavoriteQuestionService.getFavoriteList(queryDTO));
    }
}
